﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;

namespace MarioArenaLevelEditor
{
    public static class TextureManager
    {
        #region bitmaps
        //blocks
        private static Bitmap blockbrown;
        private static Bitmap chocoblock;
        private static Bitmap cloudblock;
        private static Bitmap faceblockyellow;
        private static Bitmap stoneblock;
        private static Bitmap touchedblock;
        //Grass
        private static Bitmap grasstopleft;
        private static Bitmap grasstop;
        private static Bitmap grasstopright;
        private static Bitmap grassleft;
        private static Bitmap grassmid;
        private static Bitmap grassright;
        //Pipe (vertical)
        private static Bitmap pipetopleft;
        private static Bitmap pipetopright;
        private static Bitmap pipeleft;
        private static Bitmap piperight;
        private static Bitmap pipebottomleft;
        private static Bitmap pipebottomright;
        //Pipe (horizontal)
        private static Bitmap pipelefttop;
        private static Bitmap pipeleftbottom;
        private static Bitmap pipetop;
        private static Bitmap pipebottom;
        private static Bitmap piperighttop;
        private static Bitmap piperightbottom;
        //Spawn
        private static Bitmap mariohead;
        #endregion

        /// <summary>
        /// Loads all textures.
        /// </summary>
        public static void LoadTextures()
        {
            /*Load images etc: http://msdn.microsoft.com/en-us/library/aa984367(v=vs.71).aspx */
            //LOAD IMAGES
            Stream stream;

            System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly();

            //Blocks
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.blockbrown.png");
            blockbrown = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.chocoblock.png");
            chocoblock = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.blocks.cloudblock.png");
            cloudblock = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.blocks.faceblockyellow.png");
            faceblockyellow = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.blocks.stoneblock.png");
            stoneblock = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.blocks.touchedblock.png");
            touchedblock = new Bitmap(stream);

            //Grass
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.grasstopleft.png");
            grasstopleft = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.grasstop.png");
            grasstop = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.grasstopright.png");
            grasstopright = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.grassleft.png");
            grassleft = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.grassmid.png");
            grassmid = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.grassright.png");
            grassright = new Bitmap(stream);

            //Pipe vertical
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.pipetopleft.png");
            pipetopleft = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.pipetopright.png");
            pipetopright = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.pipeleft.png");
            pipeleft = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.piperight.png");
            piperight = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.pipebottomleft.png");
            pipebottomleft = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.pipebottomright.png");
            pipebottomright = new Bitmap(stream);

            //Pipe horizontal
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.pipe_horizontal.pipelefttop.png");
            pipelefttop = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.pipe_horizontal.pipeleftbottom.png");
            pipeleftbottom = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.pipe_horizontal.pipetop.png");
            pipetop = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.pipe_horizontal.pipebottom.png");
            pipebottom = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.pipe_horizontal.piperighttop.png");
            piperighttop = new Bitmap(stream);
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.pipe_horizontal.piperightbottom.png");
            piperightbottom = new Bitmap(stream);

            //Spawnpoint
            stream = myAssembly.GetManifestResourceStream("MarioArenaLevelEditor.Resources.mario_head.png");
            mariohead = new Bitmap(stream);

        }

        /// <summary>
        /// Retrieves the Bitmap texture which the tileType represents.
        /// </summary>
        /// <param name="tileType">The number indicating a certain texture.</param>
        /// <returns>Returns the Bitmap / texture that matches the tileType.</returns>
        public static Bitmap GetMatchingTexture(int tileType)
        {
            if (tileType == 0)
                return null;
            else if (tileType == 1)
                return chocoblock;
            else if (tileType == 2)
                return blockbrown;
            else if (tileType == 3)
                return faceblockyellow;
            else if (tileType == 4)
                return touchedblock;
            else if (tileType == 5)
                return stoneblock;
            else if (tileType == 6)
                return cloudblock;
            //GRASS TILES
            else if (tileType == 10)
                return grasstopleft;
            else if (tileType == 11)
                return grasstop;
            else if (tileType == 12)
                return grasstopright;
            else if (tileType == 13)
                return grassleft;
            else if (tileType == 14)
                return grassmid;
            else if (tileType == 15)
                return grassright;
            //PIPE TILES VERTICAL
            else if (tileType == 20)
                return pipetopleft;
            else if (tileType == 21)
                return pipetopright;
            else if (tileType == 22)
                return pipeleft;
            else if (tileType == 23)
                return piperight;
            else if (tileType == 24)
                return pipebottomleft;
            else if (tileType == 25)
                return pipebottomright;
            //PIPE TILES HORIZONTAL
            else if (tileType == 26)
                return pipelefttop;
            else if (tileType == 27)
                return pipeleftbottom;
            else if (tileType == 28)
                return pipetop;
            else if (tileType == 29)
                return pipebottom;
            else if (tileType == 30)
                return piperighttop;
            else if (tileType == 31)
                return piperightbottom;
            //SPAWNPOINT TILES
            else if (tileType == 100)
                return mariohead;
            return null;
        }
    }
}
